﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using System.Data.OleDb;
using Microsoft.ApplicationBlocks.Data;
using ERB.App_Code;

/// <summary>
/// Summary description for ArCustomer
/// </summary>

namespace ERB.App_Code.BAL.CRM
{
    public class CustomerClass
    {
        #region Properties
        public int CustomerID { get; set; }
        public int BankID { get; set; }
        public int RegencyID { get; set; }
        public int CustomerGroupID { get; set; }
        public int TermID { get; set; }
        public int StatusID { get; set; }
        public string CustomerCode { get; set; }
        public string CustomerName { get; set; }
        public string CustomerContact { get; set; }
        public string Address { get; set; }
        public string Phone { get; set; }
        public string Mobile { get; set; }
        public string Fax { get; set; }
        public string TaxCode { get; set; }
        public string BankAccount { get; set; }
        public string ImageURL { get; set; }
        public string Website { get; set; }
        public string Email { get; set; }
        public string BOID { get; set; }
        public string UserCreate { get; set; }
        public DateTime CreateDate { get; set; }
        public string UserUpdate { get; set; }
        public DateTime UpdateDate { get; set; }
        public bool IsDeleted { get; set; }
        #endregion
        public CustomerClass()
        {

        }


        public static Boolean Insert(CustomerClass cus)
        {
            int rs = 0;
            try
            {
                rs = SqlHelper.ExecuteNonQuery(DataServices.ConnectString, "sp_Customer_Insert",
                                                    cus.BankID,
                                                    cus.RegencyID,
                                                    cus.CustomerGroupID,
                                                    cus.TermID,
                                                    cus.StatusID,
                                                    cus.CustomerCode,
                                                    cus.CustomerName,
                                                    cus.CustomerContact,
                                                    cus.Address,
                                                    cus.Phone,
                                                    cus.ImageURL,
                                                    cus.Website,
                                                    cus.Email,
                                                    cus.Mobile,
                                                    cus.Fax,
                                                    cus.TaxCode,
                                                    cus.BankAccount,
                                                    cus.BOID,
                                                    cus.UserCreate);
            }
            catch { }
            bool isSuccess = false;
            if (rs > 0)
                isSuccess = true;
            return isSuccess;
        }

        public static Boolean Update(CustomerClass cus)
        {
            int rs = 0;
            try
            {
                rs = SqlHelper.ExecuteNonQuery(DataServices.ConnectString, "sp_Customer_Update",
                                                cus.CustomerID,
                                                cus.BankID,
                                                cus.RegencyID,
                                                cus.CustomerGroupID,
                                                cus.TermID,
                                                cus.StatusID,
                                                cus.CustomerCode,
                                                cus.CustomerName,
                                                cus.CustomerContact,
                                                cus.Address,
                                                cus.Phone,
                                                cus.ImageURL,
                                                cus.Website,
                                                cus.Email,
                                                cus.Mobile,
                                                cus.Fax,
                                                cus.TaxCode,
                                                cus.BankAccount,
                                                cus.BOID,
                                                cus.UserUpdate);
            }
            catch { }
            bool isSuccess = false;
            if (rs > 0)
                isSuccess = true;
            return isSuccess;
        }

        public static DataTable SelectAll(CustomerClass cus)
        {
            DataTable dt =  new DataTable();
            try
            {
                dt =  SqlHelper.ExecuteDataset(DataServices.ConnectString, "sp_Customer_SelectAll", cus.BOID).Tables[0];
            }
            catch { }
            return dt;
        }

        public static DataTable SelectByID(CustomerClass cus)
        {
            DataTable dt = new DataTable();
            try
            {
                return SqlHelper.ExecuteDataset(DataServices.ConnectString, "sp_Customer_SelectByID", cus.CustomerID, cus.BOID).Tables[0];
            }
            catch { }
            return dt;
        }

        public static DataTable SelectByName(CustomerClass cus)
        {
            DataTable dt = new DataTable();
            try
            {
                dt = SqlHelper.ExecuteDataset(DataServices.ConnectString, "sp_Customer_SelectByName", cus.CustomerName, cus.BOID).Tables[0];
            }
            catch { }
            return dt;
        }

        public static Boolean Delete(CustomerClass cus)
        {
            int rs = 0;
            try
            {
                rs = SqlHelper.ExecuteNonQuery(DataServices.ConnectString, "sp_Customer_Delete", cus.CustomerID, cus.BOID);
            }
            catch { }
            bool isSuccess = false;
            if (rs > 0)
                isSuccess = true;
            return isSuccess;
        }
    }
}